<template>
  <div>
    <h4 class="title">推荐蛋糕</h4>
    <div class="items">
      <div class="item"
        v-for="(item, index) in items"
        :key="item.id"
        @click="clickItem(item.id, index)"
        >
        <img v-lazy="item.pic" alt="">
        <div class="info">
          <h5 class="name">{{item.name}}</h5>
          <p class="desc">{{item.characteristic?item.characteristic:'暂无描述' | filterDesc }}</p>
          <div class="price-tubiao">
            <span class="price">￥{{item.minPrice}}</span>
            <van-icon @click.stop="clickCart(item.id, index)" class-prefix="icon" name="gouwuche" color="red" size="20"/>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    items: {
      type: Array,
      required: true
    }
  },
  methods: {
    clickCart (id, index) {
      this.$emit('clickCart', { id, index })
    },
    clickItem (id, index) {
      this.$emit('clickItem', { id, index })
    }
  },
  filters: {
    filterDesc (v, len = 10) {
      if (v.length > 10) {
        return v.substr(0, len) + '...'
      } else {
        return v
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.title{
  text-align: center;
  line-height: 40px;
  font-weight: 700;
  font-size: 20px;
  color: #333;
}
.item{
  padding:8px;
  background-color: #fff;
  height: 200px;
  display: flex;
  padding: 5px;
  border-radius: 8px;
    img{
      width: 180px;
      height: 180px;
    }
  .info{
    flex: 1;
    padding-left: 20px;
    .name{
      padding-top: 30px;
      line-height: 30px;
    }
    .desc{
      font-size: 12px;
      color: #333;
      padding-top: 20px;
    }
    .price-tubiao{
      margin-top: 30px;
      line-height: 30px;
      display: flex;
      justify-content: space-between;
      padding-right: 10px;
    }
  }
}
</style>
